<template>
  <div class="app-container">
    <br>
    <el-table v-loading="loading" :data="tableData" @selection-change="handleSelectionChange">
      <el-table-column
          align="center"
          prop="id"
          label="ID"
          width="50">
      </el-table-column>
      <el-table-column
          align="center"
          prop="userName"
          label="用户名称"
          width="100">
      </el-table-column>
      <el-table-column
          align="center"
          prop="name"
          label="医师名称"
          width="80">
      </el-table-column>
      <el-table-column
          align="center"
          prop="sex"
          label="性别"
          width="50"
      >
      </el-table-column>
      <el-table-column
          align="center"
          prop="age"
          label="年龄"
          width="50"
      >
      </el-table-column>
      <el-table-column
          align="center"
          prop="city"
          label="城市"
          width="100"
      >
      </el-table-column>
      <el-table-column
          align="center"
          prop="phone"
          label="手机号"
          width="111"
      >
      </el-table-column>
      <el-table-column prop="positive" label="身份证正面" align="center">
        <template #default="scope">
          <el-image :src="scope.row.positive" style="width: 100px; height: 100px"></el-image>
        </template>
      </el-table-column>
      <el-table-column prop="anti" label="身份证反面" align="center">
        <template #default="scope">
          <el-image :src="scope.row.anti" style="width: 100px; height: 100px"></el-image>
        </template>
      </el-table-column>
      <el-table-column prop="certImg" label="证书图片" align="center">
        <template #default="scope">
          <el-image :src="scope.row.certImg" style="width: 100px; height: 100px"></el-image>
        </template>
      </el-table-column>
      <el-table-column prop="subTime" label="申请时间" align="center" width="160">
      </el-table-column>
      <el-table-column prop="desc" label="个人描述" align="center">
      </el-table-column>
      <el-table-column prop="status" label="状态" align="center" width="80">
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template #default="scope">
          <el-button v-show="scope.row.status === '待审核'"
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="yes(scope.row)"
          >通过
          </el-button>
          <el-button v-show="scope.row.status === '待审核'"
              size="mini"
              type="text"
              icon="el-icon-edit"
              @click="no(scope.row)"
          >不通过
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
    />

  </div>
</template>

<script>
import {selectPhy, updateStatus} from "../api/PhysicianReview"

export default {
  name: "PhysicianReview",
  data() {
    return {
      // 遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      tableData: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
      queryParams: {}
    };
  },
  created() {
    this.getList();
  },
  methods: {
    yes(row) {
      row.status = 1
      if (row.sex === '男') {
        row.sex = '0'
      } else {
        row.sex = '1'
      }
      updateStatus(row).then(res => {
        if (res.code === 200) {
          this.$message.success('审核通过')
          this.getList()
        } else {
          this.$message.error(res.msg)
        }
      })
    },
    no(row) {
      row.status = 2
      if (row.sex === '男') {
        row.sex = '0'
      } else {
        row.sex = '1'
      }
      updateStatus(row).then(res => {
        if (res.code === 200) {
          this.$message.success('审核不通过')
          this.getList()
        } else {
          this.$message.error(res.msg)
        }
      })
    },
    handleSelectionChange() {

    },
    handleUpdate() {

    },
    /*,* 查询【请填写功能名称】列表 */
    getList() {
      selectPhy(this.queryParams).then(res => {
        if (res.code === 200) {
          this.tableData = res.data
          for (const re of this.tableData) {
            if (re.status === 0) {
              re.status = '待审核'
            } else if (re.status ===1) {
              re.status = '审核通过'
            } else {
              re.status = '审核不通过'
            }
            if (re.sex === 0) {
              re.sex = '男'
            } else {
              re.sex = '女'
            }
          }
        } else {
          this.$message.error(res.msg)
        }
      })
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
  }
};
</script>

